<?php
#============================
#	Filename: online.qgmod.php
#	Note	: 客服代码
#	Version : 2.0
#	Author  : ovsexia
#	Update  : 2017-8-23
#============================
global $FS,$DB,$prefix,$bi;
$md5 = md5(LANGUAGE_ID."_online");
$cache_file = "data/cache/online_".$md5.".php";
$check_status = false;
if($iscache)
{
	$check_status = CheckCache($cache_file);
}
if($check_status)
{
	include_once($cache_file);
	unset($cache_file);
	return $catelist;
}
$sql = "SELECT * FROM ".$prefix."online WHERE ifonline=0 ORDER BY sortid ASC,id ASC";
$online = $DB->qgGetAll($sql);
if(!$online)
{
	return false;
}
else
{
	$sql = "SELECT count(id) FROM ".$prefix."online WHERE ifonline=0";
	$msg_count = $DB->qg_count($sql);
	$msg_count++;
	$boxheight = $msg_count*50+$msg_count-1;
	$boxtop = $boxheight/2;
	
	#[客服样式]
	$rs = $DB->qgGetOne("SELECT * FROM ".$prefix."online WHERE ifonline=1");
	if(!$rs)
	{
		$rs["bgcolor"] = "#3d3d3d";
		$rs["hovercolor"] = "#32aaf7";
	}
	$style .= "<style>\n";
	$style .= ".qqbox {position:fixed; top:50%; right:0; width:50px; z-index:1000;}\n";
	$style .= ".qqbox li {width:62px; height:50px; z-index:20; position:absolute; left:0;}\n";
	$style .= ".qqbox li a {background:".$rs["bgcolor"]."; display:block; color:#fff; font-size:14px; height:50px; line-height:50px; overflow:hidden; opacity:0.8; border-radius:6px;} \n";
	$style .= ".qqbox li a img {display:block; float:left; vertical-align:middle; width:24px; height:24px; margin:12px 12px 14px 14px;}\n";
	$style .= ".qqbox li a:hover {background:".$rs["hovercolor"]."; opacity:1;}\n";
	$style .= ".online_qrcode {width:200px; height:200px; position:fixed; top:50%; margin-top:-100px; right:60px; display:none;}\n";
	$style .= ".online_qrcode img {width:200px; height:200px;}\n";
	$style .= "</style>\n";

	$onlinehtml .= '<div class="qqbox" style="height:'.$boxheight.'px; margin-top:-'.$boxtop.'px;">'."\n";
	$onlinehtml .= '<ul>'."\n";
	$onlinescript .= '<script>'."\n";
	$top = 0;
	foreach($online AS $key=>$value)
	{
		if(!$value["name".$bi]){$value["name".$bi] = $value["name"];}
		if($value["type"]=="tel")
		{
			$value["kname"] = "电话";
			$value["kname_en"] = "Tel";
			$value["kname_ft"] = "電話";
			$value["kname"] = $value["kname".$bi];
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'tel:'.$value["name".$bi];
			}
		}
		elseif($value["type"]=="fax")
		{
			$value["kname"] = "传真";
			$value["kname_en"] = "Fax";
			$value["kname_ft"] = "傳真";
			$value["kname"] = $value["kname".$bi];
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'tel:'.$value["name".$bi];
			}
		}
		elseif($value["type"]=="qq")
		{
			$value["kname"] = "QQ";
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'tencent://message/?uin='.$value["name".$bi].'&Site=&Menu=yes';
			}
		}
		elseif($value["type"]=="email")
		{
			$value["kname"] = "邮箱";
			$value["kname_en"] = "E-mail";
			$value["kname_ft"] = "郵箱";
			$value["kname"] = $value["kname".$bi];
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'mailto:'.$value["name".$bi];
			}
		}
		elseif($value["type"]=="wechat")
		{
			$value["kname"] = "微信";
			$value["kname_en"] = "Wechat";
			$value["kname_ft"] = "微信";
			$value["kname"] = $value["kname".$bi];
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = "javascript:void(0)";
			}
		}
		elseif($value["type"]=="skype")
		{
			$value["kname"] = "Skype";
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'skype:'.$value["name".$bi].'?call';
			}
		}
		elseif($value["type"]=="facebook")
		{
			$value["kname"] = "Facebook";
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'javascript:void(0)';
			}
		}
		elseif($value["type"]=="twitter")
		{
			$value["kname"] = "Twitter";
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'javascript:void(0)';
			}
		}
		elseif($value["type"]=="linkin")
		{
			$value["kname"] = "Linkin";
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'javascript:void(0)';
			}
		}
		elseif($value["type"]=="whatapp")
		{
			$value["kname"] = "Whatapp";
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'javascript:void(0)';
			}
		}
		elseif($value["type"]=="pinterest")
		{
			$value["kname"] = "Pinterest";
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'javascript:void(0)';
			}
		}
		elseif($value["type"]=="youtube")
		{
			$value["kname"] = "Youtube";
			if($value["link"])
			{
				$link = $value["link"];
			}
			else
			{
				$link = 'javascript:void(0)';
			}
		}
		$width = $value["width"]-56;
		
		$cusname = "";
		if($value["cusname".$bi])
		{
			$cusname = " (".$value["cusname".$bi].")";
		}
		$onlinehtml .= '<li style="top:'.$top.'px; width:'.$value["width"].'px;"><a href="'.$link.'" target="_blank"><img src="'.SITE_URI.'images/'.$value["type"].'.png">'.$value["kname"].': '.$value["name".$bi].$cusname.'</a></li>'."\n";
		if($value["type"]=="qrcode")
		{
			$rsd = $DB->qgGetOne("SELECT * FROM ".$prefix."upfiles WHERE id='".$value["thumb"]."'");	#[缩略图]
			$onlinehtml .= '<div class="online_qrcode"><img src="'.$rsd["folder"].$rsd["filename"].'" /></div>';
			$onlinescript .= '$(".qqbox li").eq('.$key.').hover(function(){$(".online_qrcode").show();},function(){$(".online_qrcode").hide();});'."\n";
		}
		else
		{
			$onlinescript .= '$(".qqbox li").eq('.$key.').hover(function(){$(this).animate({left:-'.$width.'},300);},function(){$(this).animate({left:0},300);});'."\n";
		}
		$top = $top+51;
		if($key == count($online)-1)
		{
			$onlinehtml .= '<li style="top:'.$top.'px; width:'.$value["width"].'px;"><a href="#"><img src="'.SITE_URI.'images/retop.png"></a></li>'."\n";
		}
	}
	$onlinehtml .= '</ul>'."\n";
	$onlinehtml .= '</div>'."\n";
	$onlinescript .= '</script>'."\n";
	$onlinehtml = $onlinehtml.$onlinescript.$style;
	echo $onlinehtml;
}

$FS->qgWrite($catelist,$cache_file,"catelist");
unset($cache_file);
return $online;
?>